/*
 * Copyright 2011 Digia Oyj - Jaakko Purhonen <jaakko.purhonen@digia.com>
 */

#ifndef TRACEXPORTPROJECTSELECTWIDGET_H
#define TRACEXPORTPROJECTSELECTWIDGET_H

#include "xmlrpc/xmlrpcrequest.h"
#include <QtGui/QWidget>
#include <QtCore/QVariantList>

namespace XmlRpc {
class XmlRpcConnection;
class XmlRpcResponse;
class XmlRpcRequest;
}

namespace Trac {
namespace Internal {

namespace Ui {
    class TracExportProjectSelectWidget;
}

struct ProjectData {
    QString name;
    QString identifier;
};

class TracExportProjectSelectWidget : public QWidget
{
    Q_OBJECT
public:
    explicit TracExportProjectSelectWidget(QWidget *parent = 0);
    ~TracExportProjectSelectWidget();

    bool isValid() const;
    const QString connectionUrl();
    void initialize();
    void requestProjects();

signals:
    void validChanged(bool value);
    void errorChanged(bool value);

private slots:
    void browse();
    void rpcQueryCompleted(XmlRpc::XmlRpcResponse *response);
    void handleError(bool value);
    void checkIsValid();

private:
    Ui::TracExportProjectSelectWidget *ui;
    bool m_valid;
    XmlRpc::XmlRpcConnection *m_connection;
    XmlRpc::XmlRpcRequest m_request;
    bool m_XmlRpcError;
    QMap<int, ProjectData> m_projectData;

    void populateProjectData(QVariantList values);
    bool validateSelectProjectComboBox();
    bool validateNameLineEdit();
    bool validateIdentifierLineEdit();
    bool validateDescriptionTextEdit();
};

} // namespace Internal
} // namespace Trac

#endif // TRACEXPORTPROJECTSELECTWIDGET_H
